package demo.security.core.social.weixin.config;

import demo.security.core.props.SecurityProperties;
import demo.security.core.props.WeiXinSocialProperties;
import demo.security.core.social.SocialConfig;
import demo.security.core.social.weixin.connect.WeiXinConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

/**
 * WeiXinAutoConfig
 *
 * @author lidj
 * @date 2018-02-09
 */
@Configuration
@ConditionalOnProperty(prefix = "demo.security.socialProperties.weiXinSocialProperties",name = "appId")
public class WeiXinSocialConfig extends SocialConfig {
    @Autowired
    private SecurityProperties securityProperties;

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        WeiXinSocialProperties weiXinSocialProperties =securityProperties.getSocialProperties().getWeiXinSocialProperties();
        return new WeiXinConnectionFactory(weiXinSocialProperties.getProviderId(),weiXinSocialProperties.getAppId(),weiXinSocialProperties.getAppSecret());
    }
}
